import { checkBeforeDetectResultSubmit } from '@/api/return-factory'
import { ref } from 'vue'

/**
 * 提交检测结果前校验服务
 */
export default function () {
  const checkLoading = ref(false)
  const checkResult = ref<ReturnFactoryAPIResponse.CheckResultBeforeDetectResultSubmit>({
    goodsList: [],
    isPass: false,
  })

  const check = async (detectId: string) => {
    try {
      checkLoading.value = true
      const res = await checkBeforeDetectResultSubmit(detectId)
      checkLoading.value = false
      if (res.data.code === 20000) {
        checkResult.value = res.data.data
        return ''
      }

      return res.data.message
    } catch (error) {
      checkLoading.value = false
      return '校验失败，请稍后重试'
    }
  }

  return {
    checkResult,
    checkLoading,
    check,
  }
}
